<?php

/**
 * This is the model class for table "adjustments".
 *
 * The followings are the available columns in table 'adjustments':
 * @property integer $id
 * @property integer $value
 * @property string $date
 * @property integer $characterId
 * @property string $reason
 * @property integer $addedById
 * @property integer $updatedById
 * @property integer $raidId
 *
 * The followings are the available model relations:
 * @property Character $character
 * @property Character $addedBy
 * @property Character $updatedBy
 * @property Raids $raid
 */
class Adjustments extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Adjustments the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'adjustments';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('value, characterId, addedById, updatedById, raidId', 'numerical', 'integerOnly'=>true),
			array('reason', 'length', 'max'=>160),
			array('date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, value, date, characterId, reason, addedById, updatedById, raidId', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'character' => array(self::BELONGS_TO, 'Character', 'characterId'),
			'addedBy' => array(self::BELONGS_TO, 'Character', 'addedById'),
			'updatedBy' => array(self::BELONGS_TO, 'Character', 'updatedById'),
			'raid' => array(self::BELONGS_TO, 'Raids', 'raidId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'value' => 'Value',
			'date' => 'Date',
			'characterId' => 'Character',
			'reason' => 'Reason',
			'addedById' => 'Added By',
			'updatedById' => 'Updated By',
			'raidId' => 'Raid',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('value',$this->value);
		$criteria->compare('date',$this->date,true);
		$criteria->compare('characterId',$this->characterId);
		$criteria->compare('reason',$this->reason,true);
		$criteria->compare('addedById',$this->addedById);
		$criteria->compare('updatedById',$this->updatedById);
		$criteria->compare('raidId',$this->raidId);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}